home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: How to tell if a file exists in C
- Date: Thu, 08 Feb 96 15:11:14 GMT
- Organization: none
- Message-ID: <823792274snz@genesis.demon.co.uk>
- References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <m2buna4ugt.fsf@hawk.no>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <m2buna4ugt.fsf@hawk.no>
- jan-henrik.haukeland@fou.telenor.no "jan-henrik haukeland" writes:
-
- >Lawrence Kirby writes:
- >
- > : jan-henrik.haukeland@fou.telenor.no "jan-henrik haukeland" writes:
- > :
- > : >Use the stat function, e.g.:
- > : >
- > : >int fexist(char * filename)
- >
- ><snip>
- >
- > : This function returns 3 distinct values. As such it does not return a
- > : voolean-like quantity. Therefore it is highly misleading to label two of
- > : those return values as TRUE and FALSE - you should find some more
- > : appropriate names.
- >
- >Should I ?
-
- Definitely.
-
- >Lets see, either the file exist or it don't - Yes.
-
- No. In the general case there are 4 possibilities:
-
- 1. The file is determined to exist.
- 2. The file is determined not to exist
- 3. it isn't possible to tell (e.g. inadequate permissions on a path element)
- 4. an error occurred
-
- >Normal usage
- >of this function would be, something like:
- >
- > if ( ! fexist(filename)) {
- > /* Do stuff */
- > }
- >
- >See, either it exist or it don't - and thats Boolean.
-
- ! tests for zero or nonzero - it does *not* take a boolean operand although
- it generates a boolean-like result. x==5 also generates a boolean-like result
- but doesn't imply that x is boolean.
-
- >But as a special
- >"fyzzy logic" service, it will distinguish between TRUE, because even if it
- >is TRUE that it exist, it's maybe not so true as You would like it to be,
- >because it's NOT_A_REGULAR_FILE (i.e. a dir. a /dev ..). It is then
- >possible to test for this. Beside did I say it was a boolean function, I
- >think not.
-
- You indicated that by using TRUE and FALSE as return values. They carry
- a strong implication that the quantity is boolean-like hence they are
- the only possible values. Since that is not the case here you are
- misleading the reader. It is simply better to use names that describe the
- meaning of the values more clearly.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-